﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Catering.yl.Daily
{
    public partial class ContractorEdit : System.Web.UI.Page
    {        
        protected void Page_Load(object sender, EventArgs e)
        {            
            if(!Page.IsPostBack)
            {                
                LoadForm();
            }
        }
        public void LoadForm()
        {
            try
            {
                DataTable dt_Plan = new Catering_Rules.ContractorEdit().GetList("").Tables[0];
                dt_Plan.Columns.Add("tempId");               

                for (int i = 0; i < dt_Plan.Rows.Count; i++)
                {                  
                    dt_Plan.Rows[i]["tempId"] = i + 1;
                    for (int j = 2; j < 7; j++ )
                    {
                        if (dt_Plan.Rows[i][j] == null || dt_Plan.Rows[i][j].ToString() =="")
                            dt_Plan.Rows[i][j] = "&nbsp";
                    }
                }
                this.Rep_Plan.DataSource = dt_Plan;
                this.Rep_Plan.DataBind();
            }
            catch
            {

            }
        }
        public void changeSession(string str)
        {
            Session["DailyURL"] = str;
        }
        //添加
        [WebMethod]
        public static string Add(string CName, string LinkId, string CTel, string CAddress, string CState, string CDesc, string CType, string hdn_useDate, string hdn_currentClassID, string hdn_currentGroupID)
        {
            Catering_Model.ContractorEdit _ce = new Catering_Model.ContractorEdit();
            _ce.CName = CName;
            _ce.CPerson = LinkId;
            _ce.CPhone = CTel;
            _ce.CAddress = CAddress;
            _ce.CState = CState;
            _ce.CDesc = CDesc;
            _ce.CType = CType;
            _ce.ClassId = int.Parse(hdn_currentClassID);

            new Catering_Rules.ContractorEdit().Add(_ce);
            return "OK";
        }
        [WebMethod]
        public static ArrayList Get(string _id)
        {
            ArrayList al = new ArrayList();
            Catering_Model.ContractorEdit md = new Catering_Rules.ContractorEdit().GetModel(Convert.ToInt32(_id));
            al.Add(md.Id);
            al.Add(md.CName);
            al.Add(md.CType);
            al.Add(md.CPerson);            
            al.Add(md.CPhone);
            al.Add(md.CAddress);
            al.Add(md.CState);
            al.Add(md.CDesc);
            return al;
        }
        [WebMethod]
        public static string Edit(string _id, string CName, string LinkId, string CTel, string CAddress, string CState, string CDesc, string CType)
        {
            int id = 0;
            int areaid = 0;
            Int32.TryParse(_id, out id);
            if (id <= 0) return "NO";

            Catering_Model.ContractorEdit _CE = new Catering_Model.ContractorEdit();

            _CE.Id = id;
            _CE.CName = CName;
            _CE.CPerson = LinkId;
            _CE.CPhone = CTel;
            _CE.CAddress = CAddress;
            _CE.CState = CState;
            _CE.CDesc = CDesc;
            _CE.CType = CType;
            _CE.ClassId = int.Parse("42");
            new Catering_Rules.ContractorEdit().Update(_CE);

            return "OK";
        }
        protected void Rep_Plan_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "del")
            {
                int delID = Convert.ToInt32(e.CommandArgument);
                if (new Catering_Rules.ContractorEdit().Delete(delID))
                {
                    this.LoadForm();                    
                }
            }
            if (e.CommandName == "ChangeSession")
            {
                Session["ConMemberID"] = Convert.ToString(e.CommandArgument);
                string strOpenUrl = "window.open('ContratorMember.aspx','_self')";
                ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "onekey", strOpenUrl, true);
            }
        }       
    }
}